<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/20 0020
 * Time: 22:59
 */

namespace Lib\Core;

/**
 * @description:加载配置文件
 * @auth:yfl
 * @email:554665488@qq.com
 * Class ConfigLoad
 * @package Lib\Core
 */
class ConfigLoad
{
    /**
     * @var array:配置
     */
    public static $configMap = [];

    private static $instance;

    public static function getInstance()
    {
        if (!isset(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * 不支持热加载
     */
    public static function load()
    {
        self::$configMap = require CONFIG_PATH . '/default.php';
    }

    /**
     * 载入配置文件,可以热加载
     */
    public static function loadLazy()
    {
        $files = glob(CONFIG_PATH . '/*.php');
        if (!empty($files)) {
            foreach ($files as $dir => $file) {
                self::$configMap += include "{$file}";
            }
        }
    }

    /**
     * @param $key
     * @return bool|mixed
     * @description:获取配置
     */
    public static function get($key)
    {
        if (isset(self::$configMap[$key])) {
            return self::$configMap[$key];
        }
        return false;
    }
}